package com.iplay.service.notification.core;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.iplay.component.im.IMComponent;
import com.iplay.component.im.IMException;
import com.iplay.component.im.OutgoingMessage;

@Service
public class NotificationServiceImpl implements NotificationService{

	private static final Logger LOGGER = LoggerFactory.getLogger(NotificationServiceImpl.class);

	@Autowired
	private IMComponent imComponent;

	@Override
	@Async
	public void sendMessages(List<OutgoingMessage> messages) {
		messages.forEach(msg->{
				try {
					imComponent.sendMessage(msg);
				} catch (IMException e) {
					LOGGER.error(e.getMessage(), e);
				}
		});
	}

	@Override
	@Async
	public void sendMessage(OutgoingMessage message) {
		try {
			imComponent.sendMessage(message);
		} catch (IMException e) {
			LOGGER.error(e.getMessage(), e);
		}
	}
}
